package com.ldl.servlet.admin;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ldl.entity.Ldl;
import com.ldl.service.LdlService;
import com.ldl.service.impl.LdlServiceImpl;

/**
 * @author Administrator
 * Author : L.D.L
 * E-mail : 1419485293@qq.com
 * Date : 2020年7月29日下午8:22:33
 */
public class LdlUpdateServlet extends HttpServlet{

	private LdlService ldlService = new LdlServiceImpl();
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		Ldl ldl = new Ldl();
		ldl.setLdlName(request.getParameter("ldlName"));
		try {
			ldl.setLdlBirth(sdf.parse(request.getParameter("ldlBrithdate")));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		if(request.getParameter("ldlSex").equals("true")){
			ldl.setLdlSex("男");
		}else{
			ldl.setLdlSex("女");
		}
		ldl.setLdlAge(Integer.valueOf(request.getParameter("ldlAge")));
		ldl.setLdlId(Integer.valueOf(request.getParameter("ldlId")));
		
		try {
			ldlService.update(ldl);
			request.setAttribute("msg", "修改用户成功");
			request.setAttribute("href", "admin/ldl-list.let");
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("error", "修改用户失败:"+e.getMessage());
		}
		request.getRequestDispatcher("/admin/msg.jsp").forward(request, response);
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
}
